<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改入库单')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-entry-edit" th:object="${gysptWarehouseEntry}">
        	 <h4 class="form-header h4">单据信息</h4>
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
<!--                 <label class="col-sm-1 control-label">运单号：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{trackingNo}" class="control-label"></label> -->
<!--                 </div> -->
                <label class="col-sm-1 control-label">入库单号：</label>
                <div class="col-sm-2">
                    <label th:text="*{entryNo}" class="control-label"></label>
                </div>
                <label class="col-sm-1 control-label">入库日期：</label>
                <div class="col-sm-2">
                	<label th:text="${#dates.format(gysptWarehouseEntry.qyriq, 'yyyy-MM-dd')}" class="control-label"></label>
                </div>
                <label class="col-sm-1 control-label">仓库位置：</label>
                <div class="col-sm-2">
                	<label th:text="${warehouse?.name}" class="control-label"></label>
                </div>
            </div>
<!--             <div class="form-group">  -->
<!--             	<label class="col-sm-1 control-label">合同编号：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{nbbh}" class="control-label"></label> -->
<!--                 </div> -->
<!--                 <label class="col-sm-1 control-label">主合同名称：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{zhtmc}" class="control-label"></label> -->
<!--                 </div>    -->
<!--                 <label class="col-sm-1 control-label">分包计划编号：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{fbbh}" class="control-label"></label> -->
<!--                 </div> -->
<!--                 <label class="col-sm-1 control-label">分包名称：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{fbmc}" class="control-label"></label> -->
<!--                 </div> -->
<!--             </div> -->
<!--             <div class="form-group">     -->
<!--                 <label class="col-sm-1 control-label">项目地址：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{adress}" class="control-label"></label> -->
<!--                 </div> -->
<!--                 <label class="col-sm-1 control-label">供应商名称：</label> -->
<!--                 <div class="col-sm-2"> -->
<!--                     <label th:text="*{supplyName}" class="control-label"></label> -->
<!--                 </div> -->
<!--             </div> -->
            <div class="form-group">
                <label class="col-sm-1 control-label">备注：</label>
                <div class="col-sm-11">
                	<label th:text="*{memo}" class="control-label"></label>
                </div>
            </div>
            <h4 class="form-header h4">物料信息</h4>
            <div class="row">
                <div class="col-sm-12">
<!--                     <button type="button" class="btn btn-white btn-sm" onclick="addSpkfkRow()"><i class="fa fa-plus"> 选择材料</i></button> -->
<!--                     <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button> -->
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
          	<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "gcgl/entry";
        $("#form-entry-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-entry-edit').serialize());
            }
        }

        $("input[name='qyriq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        var data = [[${gysptWarehouseEntry.items}]];
        
        /**商品单据**/
        $(function() {
        	
	    	// 初始化数据, 可以由后台传过来
		    var options = {
		    	data: data,
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
		        columns: [{
		            checkbox: true
		        },
		        {
		        	field: 'index',
		        	align: 'center',
		        	title: "序号",
                    formatter: function (value, row, index) {
                    	//var columnIndex = $.common.sprintf("<input type='hidden' name='items[%s].xuh' value='%s'>", $.table.serialNumber(index));
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	var columnId = $.common.sprintf("<input type='hidden' name='items[%s].jine' value='%s'>", 0);
                    	var columnZdjine = $.common.sprintf("<input type='hidden' class='form-control zdjinecount' name='items[%s].zdjine' value='%s'>", row.zdjine);
                    	return columnIndex + $.table.serialNumber(index) + columnId + columnZdjine;
                    }
                },
		        {
		            field: 'mingc',
		            align: 'center',
		            title: '物料名称',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].mingc' value='%s'>", index, value);
		            	var clbhhtml = $.common.sprintf("<input type='hidden' name='items[%s].clbh' value='%s'>", index, value);
		            	var clflhtml = $.common.sprintf("<input type='hidden' name='items[%s].clfl' value='%s'>", index, value);
		        		return html + value + clbhhtml + clflhtml;
                    }
		        },{
		            field: 'clpp',
		            align: 'center',
		            title: '材料品牌',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].clpp' value='%s'>", index, value);
		        		return html +value;
                    }
		        },{
		            field: 'guig',
		            align: 'center',
		            title: '规格型号',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].guig' value='%s'>", index, value);
		        		return html +value;
                    }
		        },{
		            field: 'danw',
		            align: 'center',
		            title: '计量单位',
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].danw' value='%s'>", index, value);
		        		return html +value;
                    }
		        },{
		            field: 'shul',
		            align: 'center',
		            title: '数量',
		            width: 120,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input required class='form-control shulcount' type='hidden' name='items[%s].shul' value='%s'>", index, value);
		        		return html +value;
                    }
		        },{
		            field: 'memo',
		            align: 'center',
		            title: '备注',
		            width: 200,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input class='form-control memocount' type='hidden' name='items[%s].memo' value='%s'>", index, value);
		        		return html +value;
                    }
		        }
// 		        ,{
// 		        	field: 'id',
// 		            title: "操作",
// 		            align: "center",
// 		            width: 50,
// 		            formatter: function (value, row, index) {
// 		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].materialId' value='%s'>", index, value);
// 		                var value = $.common.isNotEmpty(row.index)
// 		                  ? row.index
// 		                  : $.table.serialNumber(index);
// 		                return html+(
// 		                  '<a class="btn btn-danger btn-xs js-btn-delete" href="javascript:void(0)" onclick="removeGoods(\'' +
// 		                  value +
// 		                  '\', \'' +
// 		                  index +
// 		                  '\')"><i class="fa fa-remove"></i>删除</a>'
// 		                );
// 		            },
// 		        }
		        ]
		    };
		    $.table.init(options);
		    
		});
        
     	// 删除按钮事件
        function removeGoods(value, index){
      	  sub.delColumnByIndex(index);
        }

		function addSpkfkRow() {
			var options = {
		       title: '选择商品',
		       url: "/gcgl/supply/submaterial",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitSpkfk
		    };
		    $.modal.openOptions(options);
		}
		
		function doSubmitSpkfk(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            for( i=0;i<rows.length;i++){
            	
            	var flag = 0;
            	var count = $("#" + table.options.id).bootstrapTable('getData').length;
            	var lis = $("#" + table.options.id).bootstrapTable('getData');
            	//判断是否重复
            	for(j=0;j<count;j++){
            		if(lis[j].id==rows[i].id){
            			flag = 1;
            			break;
            		}
            	}
            	if(flag==0){
            		var row = {
            			xh:i+1,
            			clbh: rows[i].typebh,
            			clfl: rows[i].typeName,
            			materialId: rows[i].id,
            			mingc: rows[i].mingc,
            			guig: rows[i].guig,
            			danw: rows[i].danw,
            			zdjine: rows[i].zdjine,
            			shul: 0,
            			jine: 0,
                        memo: rows[i].memo,
                        clpp: rows[i].clpp
                    }
                   	sub.addColumn(row);
            	}
            }
            
            $.modal.closeAll();
        }
    </script>
</body>
</html>